package com.lenovo.smarttraffic.Test.TestDragItem;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

import com.lenovo.smarttraffic.R;

import java.util.ArrayList;
import java.util.List;

public class DragActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<String> stringList = new ArrayList<>();
    private MesageAdapter mesageAdapter;
    String TAG="DragActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drag);
        recyclerView = (RecyclerView) findViewById(R.id.recycler_drag);
        recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
        initData();
    }


    private void initData() {

        for (int i = 0; i < 10; i++) {
            stringList.add("dassssssd"+i*10000);
        }

        mesageAdapter = new MesageAdapter(this, stringList);
        recyclerView.setAdapter(mesageAdapter);



        //置顶和删除的回调处理
        mesageAdapter.setBtnOnClickListen(new MesageAdapter.BtnOnClickListen() {
            @Override
            public void onTopListen(int position, SwipeListLayout swipeListLayout) {
                swipeListLayout.setStatus(SwipeListLayout.Status.Close, true);
                //置顶操作就是：删除当前item，再加入到集合顶部，刷新就行
                String zhiding = stringList.get(position);
                stringList.remove(position);
                mesageAdapter.notifyItemRemoved(position);
                mesageAdapter.notifyItemRangeChanged(0,stringList.size()-position);

                stringList.add(0,"置顶"+zhiding);
                mesageAdapter.notifyItemInserted(0);
                mesageAdapter.notifyItemRangeChanged(0,stringList.size()-0);
                Toast.makeText(getApplicationContext(),"置顶",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onDeleteListen(int position, SwipeListLayout swipeListLayout) {
            //      Log.e(TAG, "onDeleteListen: "+ SwipeListLayout.Status.Close);
                swipeListLayout.setStatus(SwipeListLayout.Status.Close, true);
                Toast.makeText(getApplicationContext(),"删除=="+"当前条目"+position,Toast.LENGTH_SHORT).show();
                stringList.remove(position);
                mesageAdapter.notifyItemRemoved(position);
                mesageAdapter.notifyItemRangeChanged(0,stringList.size()-position);
            //    mesageAdapter.notifyDataSetChanged();
            }
        });
    }

}
